﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.Windows.Forms;

namespace iControl
{
	class KeyMap
	{
		#region Variable Declaration
		public const string ElementName = "KeyMap";
		public const string KeyAttributeName = "Key";
		public const string UseAltKeyAttributeName = "UseAltKey";
		public const string UseControlKeyAttributeName = "UseControlKey";
		public const string UseShiftKeyAttributeName = "UseShiftKey";
		public const string CommandAttributeName = "Command";
		public const string ModifierAttributeName = "Modifiers";
		#endregion

		#region Methods
		public XElement ToXElement()
		{
			XElement xKeyMap = new XElement(ElementName,
				new XAttribute(KeyAttributeName, this.Key),
				new XAttribute(ModifierAttributeName, this.Modifiers),
				new XAttribute(CommandAttributeName, this.Command));

			return xKeyMap;
		}
		#endregion

		#region Overrides
		public override string ToString()
		{
			return string.Format("Key: {0}, UseAltKey: {1}, UseControlKey: {2}, UseShiftKey: {3}",
				this.Key);
		}
		#endregion

		#region Properties
		/// <summary>
		/// Gets bitwise combination of Modifer and Key properties.
		/// </summary>
		public Keys CompleteKey
		{
			get
			{
				return Modifiers | Key;
			}
		}

		/// <summary>
		/// Gets or sets modifer keys associated to this map.
		/// </summary>
		public Keys Modifiers { get; set; }

		/// <summary>
		/// Gets or sets key associated to this instance of KeyMap class.
		/// </summary>
		public Keys Key { get; set; }

		/// <summary>
		/// Gets or sets a value indicating command that the keyboard shortcut is mapped to.
		/// </summary>
		public ControlCommand Command { get; set; }

		/// <summary>
		/// Gets equivalent name for this instance keymap command.
		/// </summary>
		public string CommandText
		{
			get
			{
				return KeyMapValueConverter.GetEquivalentCommandText(this.Command);
			}
		}
		#endregion
	}
}
